home *** CD-ROM | disk | FTP | other *** search
/ IRIX Base Documentation 2001 May / SGI IRIX Base Documentation 2001 May.iso / usr / share / catman / p_man / cat3 / standard / matherr.z / matherr
Encoding:
Text File  |  1998-10-30  |  15.5 KB  |  892 lines

  1.  
  2.  
  3.  
  4. MMMMAAAATTTTHHHHEEEERRRRRRRR((((3333MMMM))))                                                        MMMMAAAATTTTHHHHEEEERRRRRRRR((((3333MMMM))))
  5.  
  6.  
  7.  
  8. NNNNAAAAMMMMEEEE
  9.      matherr - error-handling function
  10.  
  11. SSSSYYYYNNNNOOOOPPPPSSSSIIIISSSS
  12.      ####iiiinnnncccclllluuuuddddeeee <<<<mmmmaaaatttthhhh....hhhh>>>>
  13.  
  14.      iiiinnnntttt mmmmaaaatttthhhheeeerrrrrrrr ((((ssssttttrrrruuuucccctttt eeeexxxxcccceeeeppppttttiiiioooonnnn ****xxxx))));;;;
  15.  
  16. DDDDEEEESSSSCCCCRRRRIIIIPPPPTTTTIIIIOOOONNNN
  17.      mmmmaaaatttthhhheeeerrrrrrrr is invoked by the following functions in libmx.a when errors are
  18.      detected:
  19.  
  20.      acos acosf acosh asin asinf asinh atan atanf atan2 atan2f atanh cbrt cos
  21.      cosf cosh coshf drem erf erfc
  22.      exp expf expm1 expm1f fmod fmodf gamma hypot hypotf j0 j1 jn lgamma log
  23.      logf log10 log10f log1p log1pf
  24.      pow powf sin sinf sinh sinhf sqrt sqrtf tan tanf tanh tanhf y0 y1 yn
  25.  
  26.      Note that to use mmmmaaaatttthhhheeeerrrrrrrr, libmx.a needs to be linked with the program.
  27.      Users may define their own routines for handling errors by including a
  28.      function named mmmmaaaatttthhhheeeerrrrrrrr in their programs.  mmmmaaaatttthhhheeeerrrrrrrr must be of the form
  29.      described above.  When an error occurs, a pointer to the exception
  30.      structure _x will be passed to the user-supplied mmmmaaaatttthhhheeeerrrrrrrr function.  This
  31.      structure, which is defined in the _m_a_t_h._h header file, is as follows:
  32.  
  33.           struct exception {
  34.                int type;
  35.                char *name;
  36.                double arg1, arg2, retval;
  37.           };
  38.  
  39.      The element _t_y_p_e is an integer describing the type of error that has
  40.      occurred, from the following list of constants (defined in the header
  41.      file math.h):
  42.  
  43.           DOMAIN      argument domain error
  44.           SING        argument singularity
  45.           OVERFLOW    overflow range error
  46.           UNDERFLOW   underflow range error
  47.           TLOSS       total loss of significance
  48.           PLOSS       partial loss of significance
  49.  
  50.      The element _n_a_m_e points to a string containing the name of the function
  51.      that incurred the error.  The elements _a_r_g_1 and _a_r_g_2 are the arguments
  52.      with which the function was invoked.  _r_e_t_v_a_l is set to the default value
  53.      that will be returned by the function unless the user's mmmmaaaatttthhhheeeerrrrrrrr sets it
  54.      to a different value.
  55.  
  56.      NaN argument(s) to any of the above functions generates a call to matherr
  57.      with a domain error.
  58.  
  59.  
  60.  
  61.  
  62.  
  63.                                                                         PPPPaaaaggggeeee 1111
  64.  
  65.  
  66.  
  67.  
  68.  
  69.  
  70. MMMMAAAATTTTHHHHEEEERRRRRRRR((((3333MMMM))))                                                        MMMMAAAATTTTHHHHEEEERRRRRRRR((((3333MMMM))))
  71.  
  72.  
  73.  
  74.      If the user's mmmmaaaatttthhhheeeerrrrrrrr function returns non-zero, no error message will be
  75.      printed by the calling function, and _e_r_r_n_o will not be set.
  76.  
  77.      If mmmmaaaatttthhhheeeerrrrrrrr is not supplied by the user, the default error-handling
  78.      procedures, described by the table below, will be invoked upon error.  In
  79.      every case, _e_r_r_n_o is set to EDOM or ERANGE and the program continues.
  80.  
  81.  
  82.  
  83.  
  84.  
  85.  
  86.  
  87.  
  88.  
  89.  
  90.  
  91.  
  92.  
  93.  
  94.  
  95.  
  96.  
  97.  
  98.  
  99.  
  100.  
  101.  
  102.  
  103.  
  104.  
  105.  
  106.  
  107.  
  108.  
  109.  
  110.  
  111.  
  112.  
  113.  
  114.  
  115.  
  116.  
  117.  
  118.  
  119.  
  120.  
  121.  
  122.  
  123.  
  124.  
  125.  
  126.  
  127.  
  128.  
  129.                                                                         PPPPaaaaggggeeee 2222
  130.  
  131.  
  132.  
  133.  
  134.  
  135.  
  136. MMMMAAAATTTTHHHHEEEERRRRRRRR((((3333MMMM))))                                                        MMMMAAAATTTTHHHHEEEERRRRRRRR((((3333MMMM))))
  137.  
  138.  
  139.  
  140. _______________________________________________________________________________
  141.                       Default Error Handling Procedures
  142. ______________________________________________________________________________
  143.                                           Types of Errors
  144. ______________________________________________________________________________
  145.         type          DOMAIN   SING   OVERFLOW    UNDERFLOW   TLOSS    PLOSS
  146. ______________________________________________________________________________
  147.        errno           EDOM    EDOM    ERANGE      ERANGE     ERANGE   ERANGE
  148. ______________________________________________________________________________
  149.  EXP, EXPF:             -       -       M, H        M, 0        -        -
  150. ______________________________________________________________________________
  151.  EXPM1, EXPM1F:         -       -       M, H        M, 0        -        -
  152. ______________________________________________________________________________
  153.  LOG, LOGF:
  154.  LOG10, LOG10F:
  155.   (arg < 0)            M, N     -        -            -         -        -
  156.   (arg = 0)            M, -H    -        -            -         -        -
  157. ______________________________________________________________________________
  158.  LOG1P, LOG1PF:
  159.   (arg < -1)           M, N     -        -            -         -        -
  160.   (arg = -1)           M, -H    -        -            -         -        -
  161. ______________________________________________________________________________
  162.  POW, POWF:             -       -        +_H           0         -        -
  163.  neg ** non-int        M, 0     -        -            -         -        -
  164.    0 ** non-pos        M, H     -        -            -         -        -
  165. ______________________________________________________________________________
  166.  SQRT, SQRTF:          M, N     -        -            -         -        -
  167. ______________________________________________________________________________
  168.  DREM, FMOD, FMODF:
  169.   (arg1 = +/-inf       M, N     -        -            -         -        -
  170.    or arg2 = 0)
  171. ______________________________________________________________________________
  172.  GAMMA, LGAMMA:         -      M, H     M, H          -         -        -
  173. ______________________________________________________________________________
  174.  J0, J1, JN:            -       -        -            -        M, 0      -
  175. ______________________________________________________________________________
  176.  Y0, Y1, YN:
  177.   (arg = 0)             -       -      M, -H          -         -        -
  178.   (arg < 0)            M, N     -        -            -         -        -
  179.   (arg >= 2**49)        -       -        -            -        M, 0      -
  180. ______________________________________________________________________________
  181.  SINH, SINHF:           -       -        +_H           -         -        -
  182. ______________________________________________________________________________
  183.  COSH, COSHF:           -       -        H            -         -        -
  184. ______________________________________________________________________________
  185.  HYPOT, HYPOTF:         -       -       M, H          -         -        -
  186. ______________________________________________________________________________
  187.  ASIN, ASINF:
  188.  ACOS, ACOSF:          M, N     -        -            -         -        -
  189. ______________________________________________________________________________
  190. ______________________________________________________________________________
  191. ||||||||||||||||||||||||||||||||||||||||||||||||||
  192.  
  193.  
  194.  
  195.  
  196.  
  197.  
  198.  
  199.  
  200.  
  201.  
  202.  
  203.  
  204.  
  205.  
  206.  
  207.  
  208.  
  209.  
  210.  
  211.  
  212.  
  213.  
  214.  
  215.  
  216.  
  217.  
  218.  
  219.  
  220.  
  221.  
  222.  
  223.  
  224.  
  225.  
  226.  
  227.  
  228.  
  229.  
  230.  
  231.  
  232.  
  233.  
  234.  
  235.  
  236.  
  237.  
  238.  
  239.  
  240.                      |||||||||||||||||||||||||||||||||||||||||||||||||
  241.  
  242.  
  243.  
  244.  
  245.  
  246.  
  247.  
  248.  
  249.  
  250.  
  251.  
  252.  
  253.  
  254.  
  255.  
  256.  
  257.  
  258.  
  259.  
  260.  
  261.  
  262.  
  263.  
  264.  
  265.  
  266.  
  267.  
  268.  
  269.  
  270.  
  271.  
  272.  
  273.  
  274.  
  275.  
  276.  
  277.  
  278.  
  279.  
  280.  
  281.  
  282.  
  283.  
  284.  
  285.  
  286.  
  287.                               |||||||||||||||||||||||||||||||||||||||||||||||
  288.  
  289.  
  290.  
  291.  
  292.  
  293.  
  294.  
  295.  
  296.  
  297.  
  298.  
  299.  
  300.  
  301.  
  302.  
  303.  
  304.  
  305.  
  306.  
  307.  
  308.  
  309.  
  310.  
  311.  
  312.  
  313.  
  314.  
  315.  
  316.  
  317.  
  318.  
  319.  
  320.  
  321.  
  322.  
  323.  
  324.  
  325.  
  326.  
  327.  
  328.  
  329.  
  330.  
  331.  
  332.                                      |||||||||||||||||||||||||||||||||||||||||||||||
  333.  
  334.  
  335.  
  336.  
  337.  
  338.  
  339.  
  340.  
  341.  
  342.  
  343.  
  344.  
  345.  
  346.  
  347.  
  348.  
  349.  
  350.  
  351.  
  352.  
  353.  
  354.  
  355.  
  356.  
  357.  
  358.  
  359.  
  360.  
  361.  
  362.  
  363.  
  364.  
  365.  
  366.  
  367.  
  368.  
  369.  
  370.  
  371.  
  372.  
  373.  
  374.  
  375.  
  376.  
  377.                                                 |||||||||||||||||||||||||||||||||||||||||||||||
  378.  
  379.  
  380.  
  381.  
  382.  
  383.  
  384.  
  385.  
  386.  
  387.  
  388.  
  389.  
  390.  
  391.  
  392.  
  393.  
  394.  
  395.  
  396.  
  397.  
  398.  
  399.  
  400.  
  401.  
  402.  
  403.  
  404.  
  405.  
  406.  
  407.  
  408.  
  409.  
  410.  
  411.  
  412.  
  413.  
  414.  
  415.  
  416.  
  417.  
  418.  
  419.  
  420.  
  421.  
  422.                                                             |||||||||||||||||||||||||||||||||||||||||||||||
  423.  
  424.  
  425.  
  426.  
  427.  
  428.  
  429.  
  430.  
  431.  
  432.  
  433.  
  434.  
  435.  
  436.  
  437.  
  438.  
  439.  
  440.  
  441.  
  442.  
  443.  
  444.  
  445.  
  446.  
  447.  
  448.  
  449.  
  450.  
  451.  
  452.  
  453.  
  454.  
  455.  
  456.  
  457.  
  458.  
  459.  
  460.  
  461.  
  462.  
  463.  
  464.  
  465.  
  466.  
  467.                                                                      |||||||||||||||||||||||||||||||||||||||||||||||
  468.  
  469.  
  470.  
  471.  
  472.  
  473.  
  474.  
  475.  
  476.  
  477.  
  478.  
  479.  
  480.  
  481.  
  482.  
  483.  
  484.  
  485.  
  486.  
  487.  
  488.  
  489.  
  490.  
  491.  
  492.  
  493.  
  494.  
  495.  
  496.  
  497.  
  498.  
  499.  
  500.  
  501.  
  502.  
  503.  
  504.  
  505.  
  506.  
  507.  
  508.  
  509.  
  510.  
  511.  
  512.                                                                               ||||||||||||||||||||||||||||||||||||||||||||||||||
  513.  
  514.  
  515.  
  516.  
  517.  
  518.  
  519.  
  520.  
  521.  
  522.  
  523.  
  524.  
  525.  
  526.  
  527.  
  528.  
  529.  
  530.  
  531.  
  532.  
  533.  
  534.  
  535.  
  536.  
  537.  
  538.  
  539.  
  540.  
  541.  
  542.  
  543.  
  544.  
  545.  
  546.  
  547.  
  548.  
  549.  
  550.  
  551.  
  552.  
  553.  
  554.  
  555.  
  556.  
  557.  
  558.  
  559.  
  560.  
  561.  
  562.  
  563.  
  564.  
  565.  
  566.                                                                         PPPPaaaaggggeeee 3333
  567.  
  568.  
  569.  
  570.  
  571.  
  572.  
  573. MMMMAAAATTTTHHHHEEEERRRRRRRR((((3333MMMM))))                                                        MMMMAAAATTTTHHHHEEEERRRRRRRR((((3333MMMM))))
  574.  
  575.  
  576.  
  577.  SIN, COS, TAN:
  578.   (arg >= 2**50)       M, N     -        -            -         -        -
  579.   (arg = +/-inf)        -       -        -            -        M, 0      -
  580. ______________________________________________________________________________
  581.  SINF, COSF, TANF:
  582.   (arg >= 2**22)       M, N     -        -            -         -        -
  583.   (arg = +/-inf)        -       -        -            -        M, 0      -
  584. ______________________________________________________________________________
  585.  ATAN2, ATAN2F:        M, 0     -        -            -         -        -
  586. ______________________________________________________________________________
  587.  ACOSH:                M, N     -        -            -         -        -
  588. ______________________________________________________________________________
  589.  ATANH:
  590.   (|arg| > 1)          M, N     -        -            -         -        -
  591. ______________________________________________________________________________
  592. |||||||||||||||
  593.  
  594.  
  595.  
  596.  
  597.  
  598.  
  599.  
  600.  
  601.  
  602.  
  603.  
  604.  
  605.  
  606.                      |||||||||||||||
  607.  
  608.  
  609.  
  610.  
  611.  
  612.  
  613.  
  614.  
  615.  
  616.  
  617.  
  618.  
  619.                               |||||||||||||||
  620.  
  621.  
  622.  
  623.  
  624.  
  625.  
  626.  
  627.  
  628.  
  629.  
  630.  
  631.  
  632.                                      |||||||||||||||
  633.  
  634.  
  635.  
  636.  
  637.  
  638.  
  639.  
  640.  
  641.  
  642.  
  643.  
  644.  
  645.                                                 |||||||||||||||
  646.  
  647.  
  648.  
  649.  
  650.  
  651.  
  652.  
  653.  
  654.  
  655.  
  656.  
  657.  
  658.                                                             |||||||||||||||
  659.  
  660.  
  661.  
  662.  
  663.  
  664.  
  665.  
  666.  
  667.  
  668.  
  669.  
  670.  
  671.                                                                      |||||||||||||||
  672.  
  673.  
  674.  
  675.  
  676.  
  677.  
  678.  
  679.  
  680.  
  681.  
  682.  
  683.  
  684.                                                                               |||||||||||||||
  685.  
  686.  
  687.  
  688.  
  689.  
  690.  
  691.  
  692.  
  693.  
  694.  
  695.  
  696.  
  697.  
  698.  
  699. ______________________________________________________________________________
  700.                                 Abbreviations
  701.           M                               Message is printed
  702.           H                               HUGE is returned
  703.           -H                              -HUGE is returned
  704.           +_H                              HUGE or -HUGE is returned.
  705.           0                               0 is returned.
  706.           X                               _a_r_g_1 is returned.
  707.           N                               NaN is returned.
  708. ______________________________________________________________________________
  709. |||||||||
  710.  
  711.  
  712.  
  713.  
  714.  
  715.  
  716.  
  717.                                                                               |||||||||
  718.  
  719.  
  720.  
  721.  
  722.  
  723.  
  724.  
  725.  
  726.  
  727.  
  728.  
  729.  
  730.  
  731.  
  732.  
  733.  
  734.  
  735.  
  736.  
  737.  
  738.  
  739.  
  740.  
  741.  
  742.  
  743.  
  744.  
  745.  
  746.  
  747.  
  748.  
  749.  
  750.  
  751.  
  752.  
  753.  
  754.  
  755.  
  756.                                                                         PPPPaaaaggggeeee 4444
  757.  
  758.  
  759.  
  760.  
  761.  
  762.  
  763. MMMMAAAATTTTHHHHEEEERRRRRRRR((((3333MMMM))))                                                        MMMMAAAATTTTHHHHEEEERRRRRRRR((((3333MMMM))))
  764.  
  765.  
  766.  
  767. EEEEXXXXAAAAMMMMPPPPLLLLEEEE
  768.      /*
  769.      ** Example showing the use of libmx.a's matherr() to handle math errors.
  770.      **
  771.      **  % cc -xansi my_matherr.c -lmx
  772.      **  % a.out
  773.      **  overflow range error in logf
  774.      **  logf(0.0) is -inf.
  775.      **
  776.      **  expf failed: Argument out of domain
  777.      **  Abort (core dumped)
  778.      */
  779.  
  780.      #include <stdio.h>
  781.      #include <math.h>
  782.      #include <stdlib.h>
  783.      #include <string.h>
  784.      #include <errno.h>
  785.  
  786.      main()
  787.      {
  788.      float ff;
  789.  
  790.         ff = logf(0.0f);  /* matherr() leaves error reporting to libmx.a */
  791.         printf("logf(0.0f) is %f.\n\n",ff);
  792.         fflush(stdout);
  793.  
  794.         ff = 0.0f;
  795.         ff = 0.0f/ff;
  796.         ff = expf(ff);  /* matherr() customized to force a core dump */
  797.      }
  798.  
  799.      int matherr( register struct exception *x )
  800.      {
  801.      char *sterr;
  802.  
  803.         switch (x->type) {
  804.  
  805.         case DOMAIN:
  806.            /* if it's a NaN, abort */
  807.  
  808.            if ( isnan(x->arg1) )
  809.            {
  810.                   sterr = strerror(EDOM);
  811.                   fprintf(stderr, "%s failed: %s\n", x->name, sterr);
  812.                   abort();
  813.            }
  814.            else if ( !strcmp(x->name, "sin") )
  815.            {
  816.                   x->retval = 0.0;   /* return 0.0 */
  817.                   fprintf(stderr, "domain error in sin\n");
  818.  
  819.  
  820.  
  821.  
  822.                                                                         PPPPaaaaggggeeee 5555
  823.  
  824.  
  825.  
  826.  
  827.  
  828.  
  829. MMMMAAAATTTTHHHHEEEERRRRRRRR((((3333MMMM))))                                                        MMMMAAAATTTTHHHHEEEERRRRRRRR((((3333MMMM))))
  830.  
  831.  
  832.  
  833.                  return (1); /* suppress libmx.a error message and setting of errno */
  834.            }
  835.            else
  836.                   return (0); /* libmx.a prints error message and sets errno */
  837.         break;
  838.  
  839.         default:
  840.            return (0);    /* libmx.a prints error message and sets errno */
  841.         }
  842.      }
  843.  
  844. NNNNOOOOTTTTEEEESSSS
  845.      Errors detected by functions in libm.a can be detected by examining the
  846.      return value and/or the global variable _e_r_r_n_o.  libmx.a is provided as an
  847.      alternative error handling scheme for users who want to identify specific
  848.      kinds of errors determined by libm functions without extensive
  849.      modification of their source code.
  850.  
  851.      No extra overhead is incurred by programs using libmx.a if no error
  852.      conditions are encountered in the libmx routines.
  853.  
  854.  
  855.  
  856.  
  857.  
  858.  
  859.  
  860.  
  861.  
  862.  
  863.  
  864.  
  865.  
  866.  
  867.  
  868.  
  869.  
  870.  
  871.  
  872.  
  873.  
  874.  
  875.  
  876.  
  877.  
  878.  
  879.  
  880.  
  881.  
  882.  
  883.  
  884.  
  885.  
  886.  
  887.  
  888.                                                                         PPPPaaaaggggeeee 6666
  889.  
  890.  
  891.  
  892.